package com.bes.aiProject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bes.aiProject.entry.SxAAnalyzeMetricInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface SxAAnalyzeMetricInfoMapper extends BaseMapper<SxAAnalyzeMetricInfo> {


    @Select("select MD5(CONCAT(${groupCondition})) as condition_key,tt.* from (\n" +
            "select * , ROW_NUMBER() OVER (PARTITION BY metric_name,${groupCondition} ORDER BY metric_time DESC) AS row_num from" +
            "(select  ${groupCondition},create_time,metric_time,metric_code,metric_name,AVG(value) as value" +
            " from sx_a_analyze_metric_info where metric_time < #{lastRecordTime}" +
            "group by metric_time, metric_name,${groupCondition}) t ) tt WHERE row_num <= 100")
    List<SxAAnalyzeMetricInfo> getGroupMetric(@Param("groupCondition") String groupCondition, @Param("lastRecordTime") LocalDateTime lastRecordTime);


    @Select("select t.*, MD5(CONCAT(${groupCondition})) as condition_key  from sx_a_analyze_metric_info t where metric_time >=#{lastRecordTime}")
    List<SxAAnalyzeMetricInfo> getPredictMetric(@Param("groupCondition") String groupCondition, @Param("lastRecordTime") LocalDateTime lastRecordTime);

}
